<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2016-04-13
 * Time: 10:31
 */

function set_admin_session_aray($array){
    $_SESSION[get_kv_val('session_pix').'admin'] = $array;
}

function get_admin_session_array(){
    if(!isset($_SESSION[get_kv_val('session_pix').'admin']))
        $_SESSION[get_kv_val('session_pix').'admin']= array();
    return $_SESSION[get_kv_val('session_pix').'admin'];
}

function clean_admin_session_array(){
    unset($_SESSION[get_kv_val('session_pix').'admin']);
}

function get_left_menu_ace_admin($parent_id){
    $menu_model = D('Menu');
    //查询出一级菜单
    $str = '<ul class="nav nav-list">';
    $menu_list = $menu_model->queryField('parentid', $parent_id);
    foreach($menu_list as $k => $v){
        $cur_menu = $menu_list[$k];
        $str .= '<li class="open"><a class="parent" href="#'.$cur_menu['id'].'" class="dropdown-toggle"><span class="menu-text">';
        $str .= LANG($cur_menu['name']);
        $str .= '</span><b class="arrow fa fa-angle-down"></b></a>';
        $str .= '<ul class="submenu">';
        $menu_list_se = $menu_model->queryField('parentid', $cur_menu['id']);
        foreach($menu_list_se as $sk => $sv){
            $cur_menu_se = $menu_list_se[$sk];
            $str .= '<li><a class="child" href="/'.$cur_menu_se['m'].'/'.$cur_menu_se['c'].'/'.$cur_menu_se['a'].'" target="right"><i class="menu-icon fa fa-caret-right"></i>';
            $str .= LANG($cur_menu_se['name']);
            $str .= '</a></li>';
        }
        $str .= '</ul>';
        $str .= '</li>';
    }
    $str .= '</ul>';
    return $str;
}

/**
 * @param $parent_id
 * 返回从li开始的拼接字符串
 */
function get_menu_ace_admin($parent_id, $index = 0){
    if(!$index){
        $str = '<ul class="nav nav-list">';
    }else{
        $str = '<ul class="submenu">';
    }
    static $menu_model;
    if(!$menu_model){
        $menu_model = D('Menu');
    }
    $menu_list = $menu_model->queryField('parentid', $parent_id);
    foreach($menu_list as $k => $v){
        $index ++;
        $cur_menu = $menu_list[$k];
        if(!$menu_model->has_child($cur_menu['id'])){
            $str .= '<li class="open"><a class="child" href="http://www.baidu.com" target="right"><i class="menu-icon fa fa-caret-right"></i>';
            $str .= LANG($cur_menu['name']);
            $str .= '</a></li>';
        }else{
            $str .= '<li class="open"><a class="parent" href="#'.$cur_menu['id'].'" class="dropdown-toggle"><span class="menu-text">';
            $str .= LANG($cur_menu['name']);
            $str .= '</span><b class="arrow fa fa-angle-down"></b></a>';
            $str .= get_left_menu_ace_admin($cur_menu['id'], $index);
            $str .= '</li>';
        }
    }
    $str .= '</ul>';
    return $str;
}

function role_cat_priv_checked($priv_array, $current){
    if(in_array($current, $priv_array)){
        return 'checked="checked"';
    }
    return '';
}